﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using System.Web.Routing;
namespace SQT.tracnghiem.Admin.SystemSettings.Control.Ajax.Menu
{
    public partial class Menu_edited : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = int.Parse(Request.QueryString["id"]);
            int parent = int.Parse(Request.QueryString["parent"]);
            string name = Request.QueryString["name"];
            string icon = Request.QueryString["icon"];
            string url = Request.QueryString["url"];
            string routing = Request.QueryString["routing"];
            int update = int.Parse(Request.QueryString["update"]);
            bool isupdate = false;
            if (update==1)
                isupdate = true;

            new TblAdminMenuController().Update(id, name, icon, null, null, int.Parse(Session["admin_id"].ToString()), DateTime.Now, isupdate, null, null, parent, url, routing,null,null, null);
            RouteTable route = new RouteTable();
            RegisterRoutes(RouteTable.Routes);
        }
        public void RegisterRoutes(RouteCollection routes)
        {
            routes.Clear();
            routes.MapPageRoute("Login", "login", "~/Login.aspx");
            routes.MapPageRoute("DefaultAdmin", "quan-ly/tong-quan", "~/Admin/DefaultAdmin.aspx");
            routes.MapPageRoute("Gallery", "quan-ly/thu-vien", "~/Admin/Gallery.aspx");
            var get_submenu = new TblAdminMenuController().FetchAll().Where(x => x.AmIsDelete == false && x.AmParentID != 0);
            foreach (TblAdminMenu submenu in get_submenu)
            {
                routes.MapPageRoute(submenu.AmName, submenu.AmRouting, submenu.AmUrl);
            }
            routes.MapPageRoute("Staff_Personal", "quan-ly/trang-ca-nhan-{id}", "~/Admin/Staff_Personal.aspx");
            routes.MapPageRoute("Home", "trang-chu", "~/Default.aspx");
            routes.MapPageRoute("Alphabets", "bang-chu-cai", "~/Alphabets.aspx");
            routes.MapPageRoute("About", "gioi-thieu", "~/About.aspx");
            routes.MapPageRoute("Study_Weekly", "lich-hoc", "~/Study_Weekly.aspx");
            routes.MapPageRoute("News", "tin-tuc", "~/BaiViet/News.aspx");
            routes.MapPageRoute("Authentication", "dang-nhap", "~/Authentication.aspx");
            routes.MapPageRoute("Personal", "trang-ca-nhan-{id}", "~/Personal.aspx");
            routes.MapPageRoute("Multiple-choice", "trac-nghiem/chon-de", "~/TracNghiem/Multiple-choice.aspx");
            routes.MapPageRoute("Result", "trac-nghiem/ket-qua-{id}", "~/TracNghiem/Result.aspx");
            routes.MapPageRoute("Test", "trac-nghiem/{nameEn}-{id}", "~/TracNghiem/Task.aspx");
            routes.MapPageRoute("404", "not-found", "~/404error.html");
            routes.MapPageRoute("Lesson", "giao-an/chon-bai-giang", "~/GiaoAn/Lesson.aspx");
            routes.MapPageRoute("PartOfLesson", "giao-an/{nameEn}-{id}", "~/GiaoAn/PartOfLesson.aspx");
            routes.MapPageRoute("NewsCategories", "danh-muc/{nameEn}-{id}", "~/BaiViet/NewsCategories.aspx");
            routes.MapPageRoute("NewsReading", "bai-viet/{nameEn}-{id}", "~/BaiViet/NewsReading.aspx");
            routes.MapPageRoute("NewsTags", "tags/{nameEn}-{id}", "~/BaiViet/NewsTags.aspx");
            routes.MapPageRoute("NewsSearch", "tim-kiem/tu-khoa", "~/BaiViet/NewsSearch.aspx");
            routes.MapPageRoute("Contact", "lien-he", "~/Contact.aspx");
        }
    }
}